package com.zrrd.yt.product.api;


import com.zrrd.yt.common.result.Result;
import com.zrrd.yt.model.product.*;
import com.zrrd.yt.product.service.BaseAttrService;
import com.zrrd.yt.product.service.SkuInfoService;
import com.zrrd.yt.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/product/inner")
public class ProductApiController {

    @Autowired
    private SkuInfoService skuInfoService;
    @Autowired
    private TrademarkService trademarkService;
    @Autowired
    private BaseAttrService baseAttrService;

    //获取sku基本信息（包含图片）
    @GetMapping("/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId) throws InterruptedException {
        return skuInfoService.getSkuInfo(skuId);
    }

    //获取sku分类信息（包含三个分类）
    @GetMapping("/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long cayegory3Id){
        return skuInfoService.getCategoryView(cayegory3Id);
    }

    //获取sku价格
    @GetMapping("/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable("skuId") Long skuId){
        return skuInfoService.getSKuPrice(skuId);
    }

    //获取销售属性（spu的销售属性以及属性值并且标记了sku选择的哪个）
    @GetMapping("/getSpuSaleAttrListBySku/{spuId}/{skuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListBySku(@PathVariable("spuId") Long spuId,
                                                     @PathVariable("skuId") Long skuId){
        return skuInfoService.selectSpuSaleAttrListBySku(spuId,skuId);
    }

    //根据spuid查询sku销售属性值信息
    @GetMapping("/getSkuSaleAttrValueBySpu/{spuId}")
    public Map getSkuSaleAttrValueBySpu(@PathVariable("spuId") Long spuId){
        System.out.println("商品服务获取收到请求====>");
        System.out.println("获取的业务层Map====>"+skuInfoService.selectSkuSaleAttrValueBySpu(spuId));
        return skuInfoService.selectSkuSaleAttrValueBySpu(spuId);
    }

    //获取全部分类信息
    @GetMapping("/getBaseCategoryList")
    public Result getBaseCategoryList(){
        return Result.ok(skuInfoService.getBaseCategoryListJson());
    }

    //根据品牌id查询品牌
    @GetMapping("/getTrademark/{tmId}")
    public BaseTrademark getTrademark(@PathVariable("tmId") Long tmId){
        return trademarkService.getById(tmId);
    }

    //根据skuid查询平台属性以及属性值
    @GetMapping("/getBaseAttrInfo/{skuId}")
    public List<BaseAttrInfo> getBaseAttrInfo(@PathVariable("skuId") Long skuId){
        return baseAttrService.selectBaseAttrInfoListBySkuId(skuId);
    }

}
